import { createStore } from 'vuex'
// 引入菜单管理仓库
import menu from './modules/menu'
// 引入角色管理仓库
import role from './modules/role'
// 引入管理员管理仓库
import user from './modules/user'
interface userState {
  userInfo: Array<Object>
}
export default createStore({
  state: {
    // 管理员信息
    userInfo: JSON.parse(sessionStorage.getItem('userInfo') + '') || []
  },
  mutations: {
    REQ_USERINFO (state: userState, payload) {
      return (state.userInfo = payload)
    }
  },
  actions: {
    setUserInfo_Action ({ commit }: any, payload: any) {
      // 将管理员信息存入本地进行持久化保存
      sessionStorage.setItem('userInfo', JSON.stringify(payload))
      commit('REQ_USERINFO', payload)
    }
  },
  getters: {
    getUser (state: userState) {
      return state.userInfo
    }
  },
  modules: {
    menu,
    role,
    user
  }
})
